package com.youmeek.ssm.module.user.servlets;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 作者  Administrator
 * 时间  2017/7/10 15:24
 * 文件  ssm
 * 描述  加载一些初始化内容到内存中(ServletContext) 全局可用
 */
public class InitParamsServlet extends HttpServlet {

	@Override
	public void init() throws ServletException {
		super.init();
		Map<String,Object> sysParam = new HashMap<String,Object>();
		Map<String,String> supType = new HashMap<String,String>();
		supType.put("1", "普通供应商");
		supType.put("2", "一级供应商");
		supType.put("3", "二级供应商");

		Map<String,String> goodsColor = new HashMap<String,String>();
		goodsColor.put("red", "红色");
		goodsColor.put("green", "绿色");
		goodsColor.put("blue", "蓝色");

		sysParam.put("goodsColor", goodsColor);
		sysParam.put("supType", supType);
		ServletContext application =this.getServletContext();
		application.setAttribute("sysParam",sysParam);
		System.out.println("=======初始化完成，已加载数据字典数据=======");

	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("获取一级颜色："+getServletContext().getAttribute("sysParam"));
	}
}
